*****************************************************************************
*** load data.dta ***********************************************************
*** ssc install rdrobust ****************************************************
*** file paths (e.g. after save command) removed to ensure anonimty *********
*****************************************************************************


**Appendix 5: Summary Statistics**

sum $x sdvote threshold

***Figure 1 - Histogram***
graph set window fontface "Garamond"
hist cent_sdvote3, ///
	scheme(s2mono) w(0.5) xline(0, lpattern(dash)) percent color(gs10%40) ///
	graphregion(c(white)) ylabel(0(2)8, nogrid angle(horizontal)) ///
	ytitle("Percentage of Observations") xtitle("Share of SD Votes Adjusted by Natural Electoral Threshold")
	
***Figure 2 - Main model***	
set scheme s2mono
rdrobust $y $x, kernel(triangular) p(1) bwselect(mserd) all covs(k* y*) masspoints(off) stdvars(on) vce(nncluster KOMMUNKOD )  

rdplot $y $x if -e(h_l)<= $x & $x <= e(h_r), binselect(esmv) kernel(triangular) h(`e(h_l)' `e(h_r)') p(1) bwselect(mserd) all covs(k* y*) graphregion(margin(zero) color(white)) plotregion(style(none) color(white))  masspoints(off) stdvars(on)  ci(95) 	bgcolor(white)	graph_options(note("(2.1)", position(11)) leg(off) name(graph1_p1, replace)) 
  

rdrobust $y $x, kernel(triangular) p(2) bwselect(mserd) all covs(k* y*) masspoints(off) stdvars(on) vce(nncluster KOMMUNKOD )  

rdplot $y $x if -e(h_l)<= $x & $x <= e(h_r), ///
       binselect(esmv) kernel(triangular) h(`e(h_l)' `e(h_r)') p(1) bwselect(mserd) all covs(k* y*) graphregion(margin(zero) color(white)) plotregion(style(none) color(white))  masspoints(off) stdvars(on)   ci(95) graph_options(note("(2.2)", position(11))leg(off) name(graph1_p2, replace)))
	   
 	   	   
graph combine graph1_p1.gph graph1_p2.gph,  col(2) xsize(11) ysize(4) ///
	graphregion(margin(zero) color(white)) scale(2) plotregion(style(none) color(white)) commonscheme name(fig1)

	
	
*** Appendix 1: Parametric RD-model ***
rdrobust $y $x, ///
        kernel(uniform) p(3) h(2.52 22.19) all covs(k* y*) masspoints(off) stdvars(on) vce(nncluster KOMMUNKOD )  

rdplot $y $x, ///
       binselect(esmv) kernel(uniform) p(3) h(2.52 22.19) all covs(k* y*) masspoints(check) stdvars(on) vce(nncluster KOMMUNKOD )  graph_options(graphregion(margin(small)) scheme(sj) leg(off))

	   
*** Appendix 2: Non-optimal Bandwidths ***

rdrobust $y $x, kernel(triangular) p(1) h(0.75035) all covs(k* y*) masspoints(off) stdvars(on) vce(nncluster KOMMUNKOD )	

rdplot $y $x if -e(h_l)<= $x & $x <= e(h_r), ///
       binselect(esmv) kernel(triangular) h(`e(h_l)' `e(h_r)') p(1)  all covs(k* y*) masspoints(off) stdvars(on) vce(nncluster KOMMUNKOD )  graph_options(graphregion(margin(small)) scheme(sj) leg(off)) ///
	   		name(bandwidth_half, replace)
graph save bandwidth_half.gph, replace
	   
rdrobust $y $x, kernel(triangular) p(1) h(3.0014) all covs(k* y*) masspoints(off) stdvars(on) vce(nncluster KOMMUNKOD )

rdplot $y $x if -e(h_l)<= $x & $x <= e(h_r), ///
       binselect(esmv) kernel(triangular) h(`e(h_l)' `e(h_r)') p(1)  all covs(k* y*) masspoints(off) stdvars(on) vce(nncluster KOMMUNKOD )  graph_options(graphregion(margin(small)) scheme(sj) leg(off)) ///
	   		name(bandwidth_double, replace)
graph save bandwidth_double.gph, replace	

graph combine bandwidth_half.gph bandwidth_double.gph,  col(2) xsize(11) ysize(4) ///
	graphregion(margin(zero)) scale(2) scheme(sj) commonscheme
	      
	
** Figure 3: Municipalities with one constituency **	

keep if val_dist == 1

rdrobust $y $x, kernel(triangular) p(1) bwselect(mserd) all covs(k* y*) masspoints(off) stdvars(on) vce(nncluster KOMMUNKOD ) 

rdplot $y $x if -e(h_l)<= $x & $x <= e(h_r), binselect(esmv) kernel(triangular) h(`e(h_l)' `e(h_r)') p(1) bwselect(mserd) all covs(k* y*) graphregion(margin(zero) color(white)) plotregion(style(none) color(white))  masspoints(off) stdvars(on)  ci(95) 		graph_options(note("(3)", position(11)) leg(off) name(graph2_p1, replace)) 

rdrobust $y $x, kernel(triangular) p(2) bwselect(mserd) all covs(k* y*) masspoints(off) stdvars(on) vce(nncluster KOMMUNKOD )

